//package com.many.backs.handler;
//
//import com.many.common.constants.NosqlKeyManager;
//import com.many.common.exception.CommonException;
//import com.many.data.entity.SysUserLogin;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.MessageSource;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.http.HttpMethod;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * Created by Administrator on 2020/12/12.
// */
//@Component
//public class BackstageInterceptorHandle implements HandlerInterceptor {
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(BackstageInterceptorHandle.class);
//
//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private MessageSource messageSource;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CommonException {
//        System.out.println("执行了preHandle方法");
//        if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
//            return true;
//        }
//        String token = request.getHeader("token");
//        if (StringUtils.isEmpty(token)) {
//            thrown("00005","token为空");
//        }
//        if(!redisTemplate.hasKey(NosqlKeyManager.SYS_USER_TOKEN + "::" + token)){
//            thrown("00005","访问TOKEN过期");
//        }
//        SysUserLogin loginModel = (SysUserLogin) redisTemplate.opsForValue().get(NosqlKeyManager.SYS_USER_TOKEN + "::" + token);
//        if(loginModel == null || !StringUtils.equals(token, loginModel.getToken())){
//            thrown("00005","访问TOKEN过期");
//        }
//        return true;
//    }
//
//
//    protected void thrown(String code, String msg) throws CommonException {
//        throw new CommonException(code, msg);
//    }
//}
